<?php
/**
 * 发布器-我的收藏
 */

use Biz\service\wiki\Wiki as sWiki;
use Biz\tools\helper\Common;
use Doraemon\cache\UserCounter;
use Doraemon\tools\BlockType;
use Doraemon\tools\StatSign;

class FavListAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_REGISTER;

    public function main()
    {
        $currUid = $this->uid;
        if (!$currUid) {
            throw new \Exception("请登录重试！");
        }

        $uid = $this->getRequest()->getQuery('uid', 0);
        $page = $this->getRequest()->getQuery('page', 0);
        $pageName = $this->getRequest()->getQuery('page_name', 'inventory_page');
        $pageSize = 20;

        $platform = $this->getRequest()->getQuery('platform', '');
        if (!$uid) {
            $uid = $currUid;
        }

        $list = sWiki::getFavList($uid, $currUid, $page, $pageSize, $pageName);
        $list['list'] = Common::getWikiList($list['list']);
        if ($platform == 'node') \Doraemon\tools\HhzClient::setClientVersion(StatSign::WIKI_UP_GRADE_VERSION_522);
        $list['list'] = StatSign::versionCompatible($list['list'], StatSign::WIKI_UP_GRADE_VERSION_522, BlockType::TYPE_WIKI, 'wiki' );

        $counter = UserCounter::getOne($uid);
        $list['total'] = (int)$counter['fav_spu'];

        $this->setSuccess($list);
    }
}